package cn.sso.app.client;

import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import cn.ifloat.brick.sprofile.web.common.BasicController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.filter.CorsFilter;

import javax.annotation.PostConstruct;

/**
 * @author: float 2022/11/21 11:17
 */
@RestController
@RequestMapping("client")
public class ClientController extends BasicController {

    @PostConstruct
    public void init(){
        this.logger.info("init");
    }


    @GetMapping("login")
//    @SaIgnore
    public String login() {
        this.logger.info(SaManager.getConfig().toString());
//        StpUtil.login("float");
//        SaSession session = StpUtil.getSession();
//        StpUtil.login
        return "login";
    }

    @SaCheckPermission(value = "a.home1" )
    @SaCheckRole(value = "e")
    @GetMapping("home1")
    public String home1(){
        throw new  RuntimeException("home1 exception");
//        return "home1";
    }
//    @SaCheckPermission(value = "a.home2" ,orRole = "a")
    @GetMapping("home2")
    public String home2(){
        return "home2";
    }
//    @SaCheckPermission("a.home3")
    @GetMapping("home3")
    public String home3(){
        int i=10/0;
        return "home3";
    }
//    @SaCheckPermission("a.home4")
    @GetMapping("home4")
    public String home4(){
        return "home4";
    }

    @GetMapping("logout")
    public String logout(){
//        StpUtil.logout();
        return "logout";
    }
}
